<?php
$this->headTitle('Phân quyền','append');
?>
<div class="grid">
    <div class="breadcrumbs">
        <a class="item-1" href="/index">Trang chủ</a> › 
        <a class="item-2" href="/default/role"><?php $title = $this->headTitle(); if(isset($title[0])) echo $title[0]; ?></a> › 
        <a class="item-3" href="/default/role/add">Thêm</a>
        <div class="clear-both"></div>
    </div>
    <div class="box header">Thêm quyền mới</div>
    <div class="box content">
        <?php
            if(isset($this->mess)){
                if($this->flag == 'success')
                    echo '<div class="notification success">',$this->mess,'</div>';
                elseif($this->flag == 'alert')
                    echo '<div class="notification alert">',$this->mess,'</div>';
                else
                    echo '<div class="notification error">',$this->mess,'</div>';
            }
        ?>
        <form id="form" class="form-option" method="post" action="" enctype="multipart/form-data" name="form">
            <dl class="zend_form">
                <dt><label>Tên quyền</label></dt>
                <dd><input type="text" id="roleName" name="roleName" value=""/></dd>
                <div class="clear-both"></div>
                <dt><label>Đối Tác</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_partnerId"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                                <ul>
                                <?php 
                                    foreach ($this->partnerList as $partner){
                                        echo "<li><input type='checkbox' typerole='partner' class='partnerId' name='partnerId[]' value='{$partner['partnerId']}'><label>{$partner['partnerName']}</label></li>";
                                    }
                                ?>
                                </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div id="game">
                
                </div>
                 <div class="clear-both"></div>
               
                <dt><label>Chức năng admin Tool</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_resource_admin_tool"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                            <ul>
                            <?php 
                                foreach ($this->resourceList as $resource){
                                    if($resource['moduleName'] == 'default')
                                        echo "<li><input type='checkbox' class='resourceIdAdminTool' name='resourceId[]' value='{$resource['resourceId']}'><label>{$resource['resourceName']}</label></li>";
                                }
                            ?>
                            </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div class="clear-both"></div>
                <dt><label>Chức năng admin KPI</label></dt>
                <dd>
                    <div class="option-wrapper">
                        <div class="fieldset">
                            <div class="legend"><input type="checkbox" id="check_all_resource_admin"/><label>Chọn hết</label></div>
                            <div class="fieldset-content">
                            <ul>
                            <?php 
                                foreach ($this->resourceList as $resource){
                                    if($resource['moduleName'] == 'admin')
                                        echo "<li><input type='checkbox' class='resourceIdAdmin' name='resourceId[]' value='{$resource['resourceId']}'><label>{$resource['resourceName']}</label></li>";
                                }
                            ?>
                            </ul>
                                <div class="clear-both"></div>
                            </div>
                        </div>
                    </div>
                </dd>
                <div class="clear-both"></div>
                
                <dd id="submit-element">
                    <input value="Thêm mới" class="button" type="submit" />
                    <input value="Reset" class="button" type="reset"/>
                </dd>
            </dl>
        </form>
    </div>
</div>
<script>
    $(document).ready(function() {
        $('.partnerId').change (function (){
            var id = $(this).val();
            if ( this.checked ) {
            $.get("http://local.admin.partner.vn/admin/game/getgame/partnerId/"+id, function(result) { 
                   result = $.parseJSON(result);
                   $('#game').append('<div id="game'+id+'"></div>');
                    $('#game'+id).append(' <div class="clear-both"></div>   '
                        +'<dd><div class="option-wrapper_partner" style="margin-left:120px;"><div class="fieldset" >   '
                        +'<div class="legend_partner"><label >Game của '+id+'</label></div>'
                        +'<div class="fieldset-content"><ul id=game_'+id+'>'
                        +'</ul><div class="clear-both"></div></div></div> </div> </dd>'
                        );       
                   $.each(result, function(i, v){
                       var check='<li><input type="checkbox" class="gameId" name="gameId_'+id+'[]" value='+v.gameId+'> <label id="gameId">'+v.gameName+'</label></li>';
                         $('#game_'+id).append($(check)) ;
                   });
            })
            }
            if(!this.checked){
                $('#game'+id).empty();
            }
        });
        
    });
     
</script>